package com.xwh.article.controller;

import com.xwh.article.controller.dto.SoftwareDto;
import com.xwh.article.controller.param.SoftwareParam;
import com.xwh.article.entity.Software;
import com.xwh.article.service.SoftwareService;
import com.xwh.core.controller.BaseController;
import com.xwh.core.dao.Page;
import com.xwh.core.dto.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author xwh
 **/

@RestController
@RequestMapping("/software")
@Tag(name = "应用:软件管理")
@Slf4j
@RequiredArgsConstructor
public class SoftwareController extends BaseController {

    final SoftwareService softwareService;

    @Operation(summary = "新增一个软件")
    @PostMapping("/save")
    public Result save(@RequestBody SoftwareDto software) {
        softwareService.add(software);
        return success();
    }

    @Operation(summary = "获取软件列表")
    @PostMapping("/list")
    public Result list(@RequestBody SoftwareParam softwareParam) {
        Page<Software> list = softwareService.pageList(softwareParam);
        return success().add(list);
    }

    @Operation(summary = "修改一个软件")
    @PutMapping("/update")
    public Result update(@RequestBody Software software) {
        softwareService.updateById(software);
        return success();
    }

    @Operation(summary = "删除一个软件")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id) {
        softwareService.removeById(id);
        return success();
    }
}
